<!DOCTYPE html>

<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">

<title>class TJP::Robot - TJPlurker API Documentation</title>

<link type="text/css" media="screen" href="../rdoc.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
</script>

<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/navigation.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/search_index.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/search.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/searcher.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/darkfish.js"></script>


<body id="top" class="class">
<nav id="metadata">
  <nav id="home-section" class="section">
  <h3 class="section-header">
    <a href="../index.html">Home</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </h3>
</nav>


  <nav id="search-section" class="section project-section" class="initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <h3 class="section-header">
      <input type="text" name="search" placeholder="Search" id="search-field"
             title="Type to search, Up and Down to navigate, Enter to load">
    </h3>
  </form>

  <ul id="search-results" class="initially-hidden"></ul>
</nav>


  <div id="file-metadata">
    <nav id="file-list-section" class="section">
  <h3 class="section-header">Defined In</h3>
  <ul>
    <li>lib/tjplurker/robot.rb
  </ul>
</nav>

    
  </div>

  <div id="class-metadata">
    
    <nav id="parent-class-section" class="section">
  <h3 class="section-header">Parent</h3>
  
  <p class="link">Object
  
</nav>

    
    <!-- Method Quickref -->
<nav id="method-list-section" class="section">
  <h3 class="section-header">Methods</h3>

  <ul class="link-list">
    
    <li><a href="#method-c-new">::new</a>
    
    <li><a href="#method-i-add_service">#add_service</a>
    
    <li><a href="#method-i-start">#start</a>
    
  </ul>
</nav>

  </div>

  <div id="project-metadata">
    <nav id="fileindex-section" class="section project-section">
  <h3 class="section-header">Pages</h3>

  <ul>
  
    <li class="file"><a href="../GETSTART.html">GETSTART</a>
  
    <li class="file"><a href="../MAKEROBOT.html">MAKEROBOT</a>
  
    <li class="file"><a href="../README.html">README</a>
  
  </ul>
</nav>

    <nav id="classindex-section" class="section project-section">
  <h3 class="section-header">Class and Module Index</h3>

  <ul class="link-list">
  
    <li><a href="../Legacy.html">Legacy</a>
  
    <li><a href="../Legacy/TJPlurker.html">Legacy::TJPlurker</a>
  
    <li><a href="../Legacy/TJPlurker/NotificationData.html">Legacy::TJPlurker::NotificationData</a>
  
    <li><a href="../Legacy/TJPlurker/Robot.html">Legacy::TJPlurker::Robot</a>
  
    <li><a href="../Legacy/TJPlurker/Service.html">Legacy::TJPlurker::Service</a>
  
    <li><a href="../Legacy/TJPlurker/ThreadService.html">Legacy::TJPlurker::ThreadService</a>
  
    <li><a href="../TJP.html">TJP</a>
  
    <li><a href="../TJP/NotificationData.html">TJP::NotificationData</a>
  
    <li><a href="../TJP/Robot.html">TJP::Robot</a>
  
    <li><a href="../TJP/Service.html">TJP::Service</a>
  
    <li><a href="../TJP/TJPlurker.html">TJP::TJPlurker</a>
  
    <li><a href="../TJP/ThreadService.html">TJP::ThreadService</a>
  
  </ul>
</nav>

  </div>
</nav>

<div id="documentation">
  <h1 class="class">class TJP::Robot</h1>

  <div id="description" class="description">
    
  </div><!-- description -->

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    

    
    <!-- Attributes -->
    <section id="attribute-method-details" class="method-section section">
      <h3 class="section-header">Attributes</h3>

      
      <div id="attribute-i-tjplurker" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">tjplurker</span><span
            class="attribute-access-type">[R]</span>
        </div>

        <div class="method-description">
        
        
        
        </div>
      </div>
      
    </section><!-- attribute-method-details -->
    

    <!-- Methods -->
    
     <section id="public-class-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Public Class Methods</h3>

    
      <div id="method-c-new" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            new(tjplurker)
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            new(key, screte)
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            new(key, secret, access_token, access_token_screte)
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            key:: consumer key
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            secret:: consumer secret
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File lib/tjplurker/robot.rb, line 11</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span> *<span class="ruby-identifier">params</span>
    <span class="ruby-keyword">case</span> <span class="ruby-identifier">params</span>.<span class="ruby-identifier">size</span>
        <span class="ruby-keyword">when</span> <span class="ruby-value">1</span>
            <span class="ruby-ivar">@tjplurker</span> = <span class="ruby-identifier">params</span>[<span class="ruby-value">0</span>]
        <span class="ruby-keyword">when</span> <span class="ruby-value">2</span>
            <span class="ruby-identifier">key</span>, <span class="ruby-identifier">screte</span> = <span class="ruby-identifier">params</span>
            <span class="ruby-ivar">@tjplurker</span> = <span class="ruby-constant">TJPlurker</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">screte</span>)
        <span class="ruby-keyword">when</span> <span class="ruby-value">4</span>
            <span class="ruby-identifier">key</span>, <span class="ruby-identifier">secret</span>, <span class="ruby-identifier">access_token</span>, <span class="ruby-identifier">access_token_screte</span> = <span class="ruby-identifier">params</span>
            <span class="ruby-ivar">@tjplurker</span> = <span class="ruby-constant">TJPlurker</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">secret</span>, <span class="ruby-identifier">access_token</span>, <span class="ruby-identifier">access_token_screte</span>)
    <span class="ruby-keyword">end</span>
    <span class="ruby-ivar">@services</span> = []
<span class="ruby-keyword">end</span></pre>
          </div><!-- new-source -->
          
        </div>

        

        
      </div><!-- new-method -->

    
    </section><!-- public-class-method-details -->
  
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Public Instance Methods</h3>

    
      <div id="method-i-add_service" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">add_service</span><span
            class="method-args">(service)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <dl class="rdoc-list note-list"><dt>service
<dd>
<p>Can be instance TJPlurker::Service or class TJPlurker::Service or it’s
descendant classes.</p>
</dd></dl>
          

          
          <div class="method-source-code" id="add_service-source">
            <pre><span class="ruby-comment"># File lib/tjplurker/robot.rb, line 48</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">add_service</span> <span class="ruby-identifier">service</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">service</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Service</span>
        <span class="ruby-ivar">@services</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">service</span>
        <span class="ruby-identifier">$tjpLog</span>.<span class="ruby-identifier">info</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>){<span class="ruby-node">&quot;Add service: #{service.name}&quot;</span>}
    <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">service</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-constant">Service</span>
        <span class="ruby-identifier">tmp</span> = <span class="ruby-identifier">service</span>.<span class="ruby-identifier">new</span>
        <span class="ruby-ivar">@services</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">tmp</span>
        <span class="ruby-identifier">$tjpLog</span>.<span class="ruby-identifier">info</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>){<span class="ruby-node">&quot;Add service: #{tmp.name}&quot;</span>}
    <span class="ruby-keyword">else</span>
        <span class="ruby-identifier">$tjpLog</span>.<span class="ruby-identifier">warn</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>){<span class="ruby-string">&quot;Unrecognized service, ignored.&quot;</span>}
    <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- add_service-source -->
          
        </div>

        

        
      </div><!-- add_service-method -->

    
      <div id="method-i-start" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">start</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Starting a loop and invokes services when a notification was listened.</p>
          

          
          <div class="method-source-code" id="start-source">
            <pre><span class="ruby-comment"># File lib/tjplurker/robot.rb, line 26</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">start</span>
    <span class="ruby-identifier">$tjpLog</span>.<span class="ruby-identifier">info</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>){<span class="ruby-string">&quot;Start robot.&quot;</span>}
    <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span>{
        <span class="ruby-identifier">loop</span>{
            <span class="ruby-ivar">@tjplurker</span>.<span class="ruby-identifier">add_all_as_friends</span>
            <span class="ruby-identifier">sleep</span>(<span class="ruby-value">60</span>)
        }
    }
    <span class="ruby-identifier">loop</span>{
        <span class="ruby-ivar">@tjplurker</span>.<span class="ruby-identifier">comet_channel</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">data</span><span class="ruby-operator">|</span>
            <span class="ruby-ivar">@services</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">service</span><span class="ruby-operator">|</span>
                <span class="ruby-keyword">begin</span>
                    <span class="ruby-identifier">service</span>.<span class="ruby-identifier">serve</span>(<span class="ruby-ivar">@tjplurker</span>, <span class="ruby-identifier">data</span>)
                <span class="ruby-keyword">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">ex</span>
                    <span class="ruby-identifier">$tjpLog</span>.<span class="ruby-identifier">error</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>){<span class="ruby-node">&quot;An error occured in #{service.class}, class: #{ex.class}, message: #{ex.message}, backtrace: #{ex.backtrace}&quot;</span>}
                <span class="ruby-keyword">end</span>
            }
        }
    }
<span class="ruby-keyword">end</span></pre>
          </div><!-- start-source -->
          
        </div>

        

        
      </div><!-- start-method -->

    
    </section><!-- public-instance-method-details -->
  
  </section><!-- 5Buntitled-5D -->

</div><!-- documentation -->


<footer id="validator-badges">
  <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
  <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.
  <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
</footer>

